const { connect, P } = global



Page(global.connect(
  state => ({
    ...state.globalReducer
  }),
  dispatch => ({
    handleRoute: global.handleRoute,
    handleLicon1Tap(e) {
      console.log('handleLicon1Tap', e)
      wx.navigateBack()
    },
    handleTap(e) {
      console.log('handleTap', e)
      const { route, avatar } = e.currentTarget.dataset
      if (route) {
        this.handleRoute(e)
      }
      if (avatar) {
        this.handleAvatar(e)
      }
    },
    handleAvatar(e) {
      console.log('handleAvatar', e)
    }
  })
)(P({
  data: {
    sbpickershow1: false,
    valueList1: [0],
    ages: [],
    defaultAge: 0,

    sexs: [
      { id: 0, name: '男', checked: false },
      { id: 1, name: '女', checked: false },
    ],
    defaultSex: '',


    defaultGoodat: '',
    uiListData: [
      { id: 0, name: '店铺广告上画' },
      { id: 1, name: '店铺广告下画' },
    ]
  },
  onLoad() {
    console.log(`${this.route} onLoad`)

    const ages = []
    for (let i = 0; i < 100; i++) {
      ages.push(i)
    }
    const defaultAge = 22
    this.setData({
      defaultAge,
      valueList1: [defaultAge],
      ages
    })


    // this.handleDialog3Show()

  },
  bindAgeChange(e) {
    console.log(e)
    const defaultAge = e.detail.value
    this.setData({
      valueList1: [defaultAge]
    })
  },
  handleLogout() {
    wx.removeStorageSync('openid')
    wx.reLaunch({
      url: "/pages/login/login"
    })
  },

  // dialog1
  handleDialog1Show(e) {
    console.log('handleDialog1Show')
    setTimeout(() => {
      this.setData({
        sbpickershow1: true
      })
      this.selectComponent('#dialog1').handleShow()
    }, 10);
  },
  handleDialog1Hide(e) {
    console.log('handleDialog1Hide')
    const { defaultAge, valueList1 } = this.data
    this.setData({
      sbpickershow1: false,
      valueList1: [defaultAge]
    })
  },
  handleDialog1Confirm(e) {
    console.log('handleDialog1Confirm')
    const { valueList1 } = this.data
    this.selectComponent('#dialog1').handleClose()
    this.setData({
      defaultAge: valueList1[0],
      sbpickershow1: false,
    })
  },
  // dialog2
  handleResetSexData() {
    const { sexs, defaultSex } = this.data
    sexs.map((i) => {
      i.checked = Boolean(i.id === defaultSex)
    })
    this.setData({ sexs })
  },
  handleDialog2Show(e) {
    console.log('handleDialog2Show')
    this.selectComponent('#dialog2').handleShow()
  },
  handleDialog2Hide(e) {
    console.log('handleDialog2Hide')
    this.handleResetSexData()
  },
  handleDialog2Confirm(e) {
    console.log('handleDialog2Confirm')
    this.selectComponent('#dialog2').handleClose()
    this.setData({ defaultSex: this.data.sexs.find(i => i.checked).id })
  },
  handleCheck(e) {
    console.log('handleCheck')
    const { index } = e.currentTarget.dataset
    const { sexs } = this.data
    sexs.map(i => i.checked = false)
    sexs[index].checked = true
    this.setData({ sexs })
  },

  // dialog3
  handleDialog3Show(e) {
    this.selectComponent('#dialog3').handleShow(null, this.data.uiListData)
  },
  handleDialog3Confirm(e) {
    console.log('handleDialog3Confirm', e)
    this.setData({ defaultGoodat: e.detail })
  }
})))